#include<stdio.h>
#include<stdlib.h>

typedef struct node {
	int num;
	struct node * front;
	struct node * next;
}Node;

int insert(Node *header,int object);
int delete(Node *header,int value);
int update(Node *header,int old,int new);
int getSize(Node *header);
int getValue(Node *header,int index);
Node * initList();
void display(Node *header);

int main(){

	Node * header = initList();
	insert(header,120);
	insert(header,10);
	insert(header,20);
	printf("size=%d,index2=%d\n",getSize(header),getValue(header,2));
	delete(header,10);
	printf("size=%d,index2=%d\n",getSize(header),getValue(header,2));
	return 0;
	
}

int getSize(Node *header){
	Node * temp = header;
	int count = 0;
	while(temp->next){
		temp=temp->next;
		count++;
	}
	return count;
}
int getValue(Node *header,int index){
	Node * temp = header;
	int count = 0;
	while(temp->next){
		temp=temp->next;
		count++;
		if(count==index){
			return temp->num;
		}
	}
	return -1;
}
int update(Node *header,int old,int new){
	Node * temp = header;
	while(temp->next){
		temp=temp->next;
		if(temp->num==old){
			temp->num=new;
			return 1;
		}
	}
	return -1;
}
int delete(Node *header,int value){
	Node * temp = header;
	while(temp->next){
		temp=temp->next;
		if(temp->num==value){
			temp->front->next=temp->next;
			temp->next->front=temp->front;
			free(temp);
			return 1;
		}
	}
	return -1;
}
Node * initList(){
	Node * header=(Node*)malloc(sizeof(Node));
	header->next = NULL;
	header->front = NULL;
	return header;
}

int insert(Node * header,int value){
	if(header->next!=NULL){
		Node * temp = header;
		while(temp->next){
			temp=temp->next;
		}
		Node * p = (Node*)malloc(sizeof(Node));
		p->num = value;
		p->next = NULL;
		p->front = temp;
		temp->next=p;
	
	}else{
		Node * p = (Node*)malloc(sizeof(Node));
		p->num = value;
		p->next = NULL;
		p->front = header;
		header->next = p;
	}
}

void display(Node * header){
	if(header->next!=NULL){
		Node * temp = header;
		while(temp->next){
			temp = temp->next;
			printf("%d ",temp->num);

		
		}
		printf("\n");
	}else{
		printf("%s\n","NO ELEMENTS");
	}
}
